﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework2
{
    internal class Bank
    {
        private Dictionary<string, Account> accounts;

        public Bank()
        {
            accounts = new Dictionary<string, Account>();
            var account = new CreditAccount("123456", "123456", 0,1000);
            accounts["123456"] = account;
        }
        public void CreateAccount(string accountNumber, string password, decimal initialBalance = 0)
        {
            if (!accounts.ContainsKey(accountNumber))
            {
                var account = new Account(accountNumber, password, initialBalance);
                accounts[accountNumber] = account;
                //Console.WriteLine("账户创建成功！");
            }
            else
            {
                //Console.WriteLine("账户已存在，请尝试其他账号。");
            }
        }
        public bool CheckAccount(string accountNumber,string password)
        {
            if (accounts.ContainsKey(accountNumber))
            {
                return accounts[accountNumber].Password == password;
            }
            return false;
        }
        public decimal CheckAccountBalance(string accountNumber)
        {
            if (accounts.ContainsKey(accountNumber))
            {
                var account = accounts[accountNumber];
                return account.CheckBalance();
            }
            return -1;
        }
        public bool DepositToAccount(string accountNumber, decimal amount)
        {
            if (accounts.ContainsKey(accountNumber))
            {
                var account = accounts[accountNumber];
                account.Deposit(amount);
                return true;
            }
            return false;
        }

        public bool WithdrawFromAccount(string accountNumber, decimal amount)
        {
            if (accounts.ContainsKey(accountNumber))
            {
                var account = accounts[accountNumber];
                return account.Withdraw(amount);
            }
            return false;
        }
        public bool ChangePin(string accountNumber,string newPin)
        {
            if (accounts.ContainsKey(accountNumber))
            {
                var account = accounts[accountNumber];
                account.ChangePassword(newPin);
                return true;
            }
            return false;
        }
        public decimal GetCreditNum(string accountNumber)
        {
            if (accounts.ContainsKey(accountNumber))
            {
                var account = accounts[accountNumber];
                if(account is CreditAccount)
                {
                    return ((CreditAccount)account).CreditLimit;
                }
            }
            return 0;
        }
    }
}
